package com.spring.housing1.util;

import cn.hutool.core.util.RandomUtil;
import com.spring.housing1.constant.Constants;
import com.spring.housing1.pojo.DoctorInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;
import java.util.Map;

/*
* 患者预约时随机分配一名医师
* */
public class GetDoctorInfo {


    public static DoctorInfo getDoct(JdbcTemplate jdbcTemplate){
//        查询所有在诊影像科医生
        Map<String, Object> stringObjectMap = jdbcTemplate.queryForMap("select count(*) from web_mana_user where room_id =2 and enable =1");
        String obj =  stringObjectMap.get("count(*)").toString();
        int i = RandomUtil.randomInt(0, Integer.parseInt(obj));
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select real_name,name,id from web_mana_user where room_id =2 and enable =1");
        Map<String, Object> stringObjectMap1 = maps.get(i);
          DoctorInfo doctorInfo = new DoctorInfo();
       String real_name = stringObjectMap1.get("real_name").toString();
        String name = stringObjectMap1.get("name").toString();
        String id = stringObjectMap1.get("id").toString();
       doctorInfo.setReal_name(real_name);
     doctorInfo.setName(name);
        doctorInfo.setId(Long.parseLong(id));
        return doctorInfo;
    }
    public static DoctorInfo getLastDoctor(JdbcTemplate jdbcTemplate){
//        查询所有在诊内外科医生
        Map<String, Object> stringObjectMap = jdbcTemplate.queryForMap("select count(*) from web_mana_user where room_id =3 and enable =1");
        String obj =  stringObjectMap.get("count(*)").toString();
        int i = RandomUtil.randomInt(0, Integer.parseInt(obj));
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select real_name,name,id from web_mana_user where room_id =3 and enable =1");
        Map<String, Object> stringObjectMap1 = maps.get(i);
        DoctorInfo doctorInfo = new DoctorInfo();
        String real_name = stringObjectMap1.get("real_name").toString();
        String name = stringObjectMap1.get("name").toString();
        String id = stringObjectMap1.get("id").toString();
        doctorInfo.setReal_name(real_name);
        doctorInfo.setName(name);
        doctorInfo.setId(Long.parseLong(id));
        return doctorInfo;
    }

}
